﻿using CloudDcPc.Entity;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CloudDcPc.FuckDlg
{
    /// <summary>
    /// TabAddDlg.xaml 的交互逻辑
    /// </summary>
    public partial class TabAddDlg : Window
    {
        ObservableCollection<Tab> all_Tab = null;
        public TabAddDlg(ObservableCollection<Tab> all_Tab)
        {
            this.all_Tab = all_Tab;
            InitializeComponent();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            int tab_num;
            int size;
            try
            {
                tab_num = Int32.Parse(txt_tab_num.Text);
                size = Int32.Parse(txt_size.Text);
            }
            catch
            {
                MessageBox.Show("桌号或人数填写错误，只能是数字！");
                return;
            }
            
            string name = txt_name.Text;
            if (name == "")
            {
                MessageBox.Show("名称不能为空！");
                return;
            }
            int status = Int32.Parse(((TextBlock)cb_status.SelectedItem).Tag.ToString());
            int wait = Int32.Parse(((TextBlock)cb_wait.SelectedItem).Tag.ToString());
            Tab tab = new Tab()
            {
                Tab_num = tab_num,
                Name = name,
                Size = size,
                Status = status,
                Wait = wait
            };

            if(App.TabBean.HasTab(tab_num) || App.TabBean.HasTabByName(name)){
                MessageBox.Show("当前桌位编号或名称已经存在！");
                return;
            }
            if (App.TabBean.AddTab(tab))
            {
                MessageBox.Show("添加成功！");
                all_Tab.Add(tab);
                this.Close();
            }else{
                MessageBox.Show("添加失败！");
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
